////////////////////
// LoginState
////////////////////

import { events } from "./events";

/**
 * Use the `Browser.loginState` API to read and monitor the login state.
 *
 * Permissions: "loginState"
 * @platform ChromeOS only
 * @since Chrome 78
 */
export namespace loginState {
    export interface SessionStateChangedEvent extends events.EventDispatcher<(sessionState: SessionState) => void> { }

    /** Possible profile types. */
    export type ProfileType = "SIGNIN_PROFILE" | "USER_PROFILE";

    /** Possible session states. */
    export type SessionState = "UNKNOWN" | "IN_OOBE_SCREEN" | "IN_LOGIN_SCREEN" | "IN_SESSION" | "IN_LOCK_SCREEN";

    /** Gets the type of the profile the extension is in. */
    export function getProfileType(callback?: (profileType: ProfileType) => void): void {
        Wab.callFunction({ funcName: 'loginState.getProfileType' }).then(callback)
    }

    /** Gets the current session state. */
    export function getSessionState(callback?: (sessionState: SessionState) => void): void {
        Wab.callFunction({ funcName: 'loginState.getSessionState' }).then(callback)
    }

    /** Dispatched when the session state changes. sessionState is the new session state.*/
    export const onSessionStateChanged: SessionStateChangedEvent = new events.EventDispatcher();    
}